package com.shop2cn.iapi.coupon.testcase.old;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.ConversionCouponBean;
import com.shop2cn.iapi.coupon.service.ConversionCouponCall;
import com.shop2cn.iapi.couponmanage.parameter.CreateBagBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.executeTaskBean;
import com.shop2cn.iapi.couponmanage.service.CreateBagCall;
import com.shop2cn.iapi.couponmanage.service.CreateCall;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.executeTaskCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
//import com.ymttest.business.service.CouponCallService;
//import com.ymttest.business.service.CouponServiceCallService;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.couponbag;
import com.ymttest.database.model.couponconversion;
import com.ymttest.database.model.couponconversioncode;
import com.ymttest.database.model.coupon;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponconversionrecord;
import com.ymttest.database.sqlwapper.couponbagWapper;
import com.ymttest.database.sqlwapper.couponconversionbatchWapper;
import com.ymttest.database.sqlwapper.couponconversioncodeWapper;
import com.ymttest.database.sqlwapper.couponconversionWapper;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponconversionrecordWapper;
import com.ymttest.database.sqlwapper.couponsendsubtaskWapper;
//import com.ymttest.database.model.YmtCoupon;
//import com.ymttest.database.model.couponbatch;
//import com.ymttest.database.model.CouponConversion;
//import com.ymttest.database.model.CouponConversionCode;
//import com.ymttest.database.model.couponconversionrecord;
//import com.ymttest.database.model.YmtCouponPrivateUserBound;
//import com.ymttest.database.model.YmtCouponScenario;
//import com.ymttest.database.model.YmtCouponSetting;
//import com.ymttest.database.model.YmtCouponValue;
//import com.ymttest.database.sqlwapper.couponbatchWapper;
//import com.ymttest.database.sqlwapper.YmtCouponConversionBatchRelationWapper;
//import com.ymttest.database.sqlwapper.CouponConversionWapper;
//import com.ymttest.database.sqlwapper.CouponConversionCodeWapper;
//import com.ymttest.database.sqlwapper.couponconversionrecordWapper;
//import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
//import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
//import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
//import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
//import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*兑换优惠券
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ConversionCoupon{
	private static ConversionCouponBean conversioncouponBean;
	private static ConversionCouponCall conversioncouponCall;
	private couponbatchWapper couponbatchWapper=new couponbatchWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("兑换优惠券");
	}

	@Before
	public void caseUp() {
		conversioncouponBean=new ConversionCouponBean();
		conversioncouponCall=new ConversionCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(conversioncouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_001() {
		Logger.start(true,"兑换优惠券-随机券");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponMCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = couponMCallService.setDefaultRandomCreateBean(batchCodes);
			CreateCall createCall = couponMCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());

			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_002() {
		Logger.start(true,"兑换优惠券-自定义券");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setCouponNum(3000);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);

			
			conversioncouponBean.setUserId(TestDataManager.getRandomIntNum(8));
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_003() {
		Logger.start(true,"兑换优惠券-自定义券-指定新用户的批次，老用户兑换");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setUserType(1);

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(2);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			   Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		        Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		        Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		        Logger.verifyEquals("20", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_004() {
		Logger.start(true,"兑换优惠券-自定义券-指定老用户的批次，新用户兑换");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setUserType(2);

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(1);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			   Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		        Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		        Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		        Logger.verifyEquals("21", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_005() {
		Logger.start(true,"兑换优惠券-自定义券-兑换码不存在");
		try {
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode("asdd");
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(1);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			   Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		        Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		        Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		        Logger.verifyEquals("15", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_006() {
		Logger.start(true,"兑换优惠券-自定义券-兑换码空");
		try {
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
		
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(1);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			   Logger.verifyEquals("1", conversioncouponCall.getCode(), "验证返回code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_007() {
		Logger.start(true,"兑换优惠券-自定义券-userId不存在-服务端不做判断，coupon表的userid落0");
		try {
			
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
		   Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
	        Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_008() {
		Logger.start(true,"兑换优惠券-自定义券-超出领取数");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		    Logger.verifyEquals("2", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_009() {
		Logger.start(true,"兑换优惠券-自定义券-已过期");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			couponbatch batch = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			Date dNow = new Date(); // 当前时间
			
			  Calendar calendarstart = Calendar.getInstance(); // 得到日历
		        calendarstart.setTime(dNow);// 把当前时间赋给日历
		        calendarstart.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
		        Date dStart = calendarstart.getTime(); // 得到前一天的时间

		        Calendar calendarend = Calendar.getInstance(); // 得到日历
		        calendarend.setTime(dNow);// 把当前时间赋给日历
		        calendarend.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
		        Date dEnd = calendarend.getTime(); // 得到前一天的时间
//		    coupon coupon=new couponWapper().selectByBatchId(batch.getBatchId()).get(0); 
//			new couponWapper().setValidStart(coupon.getRecordId(), dStart);
//			new couponWapper().setValidEnd(coupon.getRecordId(), dEnd);
			new couponbatchWapper().setValidStart(batch.getBatchId(), dStart);
			new couponbatchWapper().setValidEnd(batch.getBatchId(), dEnd);
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();				
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		    Logger.verifyEquals("3", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_010() {
		Logger.start(true,"兑换优惠券-自定义券-已作废");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			new CouponShop2cnMCallService().InvalidPlatformBatch(createCouponCall.getBatchCode(), "1223", "33fdff");
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();				
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		    Logger.verifyEquals("4", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_011() {
		Logger.start(true,"兑换优惠券-自定义券-批次不存在");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			String num = TestDataManager.getRandomNum(11);
			new couponconversionbatchWapper().setcouponbatchCode(bill.getConversionId(), num);
		
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();				
			Logger.verifyEquals("2", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals(true, conversioncouponCall.getMessage().contains("批次不存在"), "验证返回Message");

//		        // 验证返回
//		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
//		                "验证返回IsReceiveSuccess(");
//		    Logger.verifyEquals("8", conversioncouponCall.getConversionFailReason(),
//		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_ConversionCoupon_012() {
		Logger.start(true,"兑换优惠券-自定义券-批次不能用于兑换");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();

			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 等待兑换码生成
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			int flag=0;
			while(CouponConversionCodes.size()<1 && flag<500)
			{
				flag++;
				Thread.sleep(200);
				CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());	
			}

			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();				
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		    Logger.verifyEquals("18", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_013() {
		Logger.start(true,"兑换优惠券-兑换码不存在");
		try {
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode("dddeewe");
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();				
			
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
		    Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");

		        // 验证返回
		    Logger.verifyEquals("false", conversioncouponCall.getConversionSuccess(),
		                "验证返回IsReceiveSuccess(");
		    Logger.verifyEquals("15", conversioncouponCall.getConversionFailReason(),
		                "验证返回ReceiveFailReason-定义参考http://172.16.22.142:83/Help/ResourceModel?modelName=ReceiveFailReasonInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_016() {
		Logger.start(true,"兑换优惠券-优惠券是套券-兑换码是自定义券");
		try {
			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();
			CreateBagBean createBagBean = mCouponserviceCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);//领取方式是套券
			CreateBagCall createBagCall = mCouponserviceCallService.createPlatformCouponBag(createBagBean);
			
			//生成批次及兑换码
			List<String> bagCodes = new ArrayList<>();
			bagCodes.add(createBagCall.getbagCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(bagCodes);
			createBean.setBatchType(2);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(2);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(), "验证返回conversionSuccess");
			
			// 验证返回
			Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(),
			"验证返回IsReceiveSuccess(");
			Logger.verifyEquals("0", conversioncouponCall.getConversionFailReason(),
			"验证返回ReceiveFailReason");
			
			// 验证表couponconversionrecord
			List<couponconversionrecord> records = new couponconversionrecordWapper().selectByConversionId(bill.getConversionId());
			Logger.verifyEquals(1, records.size(), "验证数据库表couponconversionrecord中生成条记录");
			
			if(records.size()==1)
			{
				couponconversionrecord record = records.get(0);
				Logger.verifyEquals(bill.getConversionId(), record.getConversionId(),
			        "验证数据库表couponconversionrecord中Conversionbillid");
			Logger.verifyEquals(conversioncouponBean.getConversionCode(), record.getConversionCode(),
			        "验证数据库表couponconversionrecord中Conversioncode");
			Logger.verifyEquals(conversioncouponBean.getUserId(), record.getUserId(),
			        "验证数据库表couponconversionrecord中Userid");
			}
			//验证couponbatch
		   couponbatch couponbatch = new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
	        List<coupon> coupons= new couponWapper().selectByBatchId(couponbatch.getBatchId());
	        coupon coupon=coupons.get(0);
	   
	        // 验证数据库
	        Logger.verifyEquals(conversioncouponBean.getUserId(), coupon.getUserId(),
	                "验证数据库表coupon中UserId");
	        Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
	                "验证数据库表couponbatch与表coupon中BatchId");
	        Logger.verifyEquals(coupon.getCouponCode(), conversioncouponCall.getCouponCodes().get(0), "验证返回CouponCodes");
	        Logger.verifyEquals(1, coupons.size(), "验证数据库表coupon中生成1条记录"); 
			// 平台券异步更新该字段，放到Job,后面加上
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbag couponbag=new couponbagWapper().selectByPrimaryKey(createBagCall.getbagCode());
			Logger.verifyEquals(1, couponbag.getReceivedCount(), "验证数据库表couponbag中ReceiveCount加1");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_017() {
		Logger.start(true,"兑换优惠券-优惠券是套券-兑换码是随机券");
		try {
			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();
			CreateBagBean createBagBean = mCouponserviceCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);//2：领取方式是套券
			CreateBagCall createBagCall = mCouponserviceCallService.createPlatformCouponBag(createBagBean);
			
			//生成批次及兑换码
			List<String> bagCodes = new ArrayList<>();
			bagCodes.add(createBagCall.getbagCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultRandomCreateBean(bagCodes);
			createBean.setBatchType(2);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(2);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(), "验证返回conversionSuccess");
			
			// 验证返回
			Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(),
			"验证返回IsReceiveSuccess(");
			Logger.verifyEquals("0", conversioncouponCall.getConversionFailReason(),
			"验证返回ReceiveFailReason");
			
			// 验证表couponconversionrecord
			List<couponconversionrecord> records = new couponconversionrecordWapper().selectByConversionId(bill.getConversionId());
			Logger.verifyEquals(1, records.size(), "验证数据库表couponconversionrecord中生成条记录");
			
			if(records.size()==1)
			{
				couponconversionrecord record = records.get(0);
				Logger.verifyEquals(bill.getConversionId(), record.getConversionId(),
			        "验证数据库表couponconversionrecord中Conversionbillid");
			Logger.verifyEquals(conversioncouponBean.getConversionCode(), record.getConversionCode(),
			        "验证数据库表couponconversionrecord中Conversioncode");
			Logger.verifyEquals(conversioncouponBean.getUserId(), record.getUserId(),
			        "验证数据库表couponconversionrecord中Userid");
			}
			//验证couponbatch
		   couponbatch couponbatch = new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
	        List<coupon> coupons= new couponWapper().selectByBatchId(couponbatch.getBatchId());
	        coupon coupon=coupons.get(0);
	   
	        // 验证数据库
	        Logger.verifyEquals(conversioncouponBean.getUserId(), coupon.getUserId(),
	                "验证数据库表coupon中UserId");
	        Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
	                "验证数据库表couponbatch与表coupon中BatchId");
	        Logger.verifyEquals(coupon.getCouponCode(), conversioncouponCall.getCouponCodes().get(0), "验证返回CouponCodes");
	        Logger.verifyEquals(1, coupons.size(), "验证数据库表coupon中生成1条记录"); 
			// 平台券异步更新该字段，放到Job,后面加上
			couponbag couponbag=new couponbagWapper().selectByPrimaryKey(createBagCall.getbagCode());
			Logger.verifyEquals(1, couponbag.getReceivedCount(), "验证数据库表couponbag中ReceiveCount加1");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_018() {
		Logger.start(true,"兑换优惠券-随机券-分销");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponMCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForConversion();
			//分销 修改platformSource=1
			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);
			couponbatchWapper.setPlatformSource(1, createCouponCall.getBatchCode());

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = couponMCallService.setDefaultRandomCreateBean(batchCodes);
			CreateCall createCall = couponMCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());

			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_019() {
		Logger.start(true,"兑换优惠券-自定义券-分销");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setCouponNum(3000);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			couponbatchWapper.setPlatformSource(1, createCouponCall.getBatchCode());
			
			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);

			
			conversioncouponBean.setUserId(TestDataManager.getRandomIntNum(8));
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_020() {
		Logger.start(true,"兑换优惠券-随机券-优惠券批次是相对时间-小时");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponMCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setEffectiveType(1);
			createCouponBean.setEffectiveTimeType(1);
			createCouponBean.setEffectiveDays(2);
			
			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = couponMCallService.setDefaultRandomCreateBean(batchCodes);
			CreateCall createCall = couponMCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());

			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_021() {
		Logger.start(true,"兑换优惠券-自定义券-优惠券批次是相对时间-小时");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setCouponNum(3000);
			createCouponBean.setEffectiveType(1);
			createCouponBean.setEffectiveTimeType(1);
			createCouponBean.setEffectiveDays(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);

			
			conversioncouponBean.setUserId(TestDataManager.getRandomIntNum(8));
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_022() {
		Logger.start(true,"兑换优惠券-随机券-优惠券批次是绝对时间");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponMCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setEffectiveType(0);
			
			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = couponMCallService.setDefaultRandomCreateBean(batchCodes);
			CreateCall createCall = couponMCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());

			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConversionCoupon_023() {
		Logger.start(true,"兑换优惠券-自定义券-优惠券批次是绝对时间");
		try {
			//生成批次及兑换码
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForConversion();
			createCouponBean.setCouponNum(3000);
			createCouponBean.setEffectiveType(0);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);

			CouponShop2cnMCallService mCouponserviceCallService = new CouponShop2cnMCallService();

			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());

			CreateBean createBean = mCouponserviceCallService.setDefaultCustomCreateBean(batchCodes);
			CreateCall createCall = mCouponserviceCallService.create(createBean);
		
			// 这里直接调用job接口生成兑换码
			List<Map>  tasks=new couponsendsubtaskWapper().selectTaskByTaskTypelimit(3,1);
			executeTaskCall call=new executeTaskCall();
			executeTaskBean bean=new executeTaskBean();
			
			for(int i=0;i<tasks.size();i++){
				bean.setSubTaskId(Integer.parseInt(tasks.get(i).get("SubTaskId").toString()));
				call.setData(bean);
				call.callService();
			}
			couponconversion bill = new couponconversionWapper()
					.selectByconversionName(createBean.getBillName()).get(0);
			List<couponconversioncode> CouponConversionCodes = new couponconversioncodeWapper().selectByConversionId(bill.getConversionId());
			
			// 设置值
			conversioncouponBean.setUserId(Integer.valueOf(EnvSetup.getData("BuyUserId")));
			conversioncouponBean.setConversionCode(CouponConversionCodes.get(0).getConversionCode());
			conversioncouponBean.setAppId("Ymt");
			conversioncouponBean.setRequestId("12344");
			conversioncouponBean.setUserType(0);
			
			conversioncouponCall.setData(conversioncouponBean);

			
			conversioncouponBean.setUserId(TestDataManager.getRandomIntNum(8));
			conversioncouponCall.setData(conversioncouponBean);
			conversioncouponCall.callService();	
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			Logger.verifyEquals(createBean.getGenerateQuantity(), CouponConversionCodes.size(), "验证数据CouponConversionCode中生成相应记录");
			VerifyReturn(createCouponBean,createBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void VerifyReturn(CreateCouponBean createcouponBean,CreateBean createBean)
    {
        Logger.verifyEquals("0", conversioncouponCall.getCode(), "验证返回code");
        Logger.verifyEquals("操作成功！", conversioncouponCall.getMessage(), "验证返回Message");
        Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(), "验证返回conversionSuccess");

        // 验证返回
        Logger.verifyEquals("true", conversioncouponCall.getConversionSuccess(),
                "验证返回IsReceiveSuccess(");
        Logger.verifyEquals("0", conversioncouponCall.getConversionFailReason(),
                "验证返回ReceiveFailReason");
        
        // 验证表couponconversionrecord
        couponconversion bill = new couponconversionWapper()
				.selectByconversionName(createBean.getBillName()).get(0);
        
        List<couponconversionrecord> records = new couponconversionrecordWapper().selectByConversionId(bill.getConversionId());
        Logger.verifyEquals(1, records.size(), "验证数据库表couponconversionrecord中生成条记录");
        
        if(records.size()==1)
        {
        	couponconversionrecord record = records.get(0);
        	Logger.verifyEquals(bill.getConversionId(), record.getConversionId(),
                "验证数据库表couponconversionrecord中Conversionbillid");
        	Logger.verifyEquals(conversioncouponBean.getConversionCode(), record.getConversionCode(),
                    "验证数据库表couponconversionrecord中Conversioncode");
        	Logger.verifyEquals(conversioncouponBean.getUserId(), record.getUserId(),
                    "验证数据库表couponconversionrecord中Userid");
        }
        List<String> batchCodes = createBean.getCouponBatchCodes();
        
        for (String batchCode : batchCodes) {		
		
        couponbatch couponbatch = new couponbatchWapper().selectBybatchCode(batchCode).get(0);
        List<coupon> coupons= new couponWapper().selectByBatchId(couponbatch.getBatchId());
        coupon coupon=coupons.get(0);
   
        // 验证数据库
        Logger.verifyEquals(conversioncouponBean.getUserId(), coupon.getUserId(),
                "验证数据库表coupon中UserId");
        Logger.verifyEquals(batchCode, couponbatch.getBatchCode(),
                "验证数据库表couponbatch中BatchCode");
        Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
                "验证数据库表couponbatch与表coupon中BatchId");
        
        Logger.verifyEquals(coupon.getCouponCode(), conversioncouponCall.getCouponCodes().get(0), "验证返回CouponCodes");
        Logger.verifyEquals(1, coupons.size(), "验证数据库表coupon中生成条记录");
		// 平台券异步更新该字段，放到Job,后面加上
		//	Thread.sleep(5000);
        Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中ReceiveCount");
        
        Logger.verifyEquals(couponbatch.getPlatformSource(), coupon.getPlatformSource(),
                "验证数据库表couponbatch中与coupon中的字段PlatformSource一致");
        //优惠券的是有效时间
         //优惠券的相对时间是天
        if(couponbatch.getEffectiveType()==1 && couponbatch.getEffectiveTimeType()==0)
        {
			Logger.verifyEquals(couponbatch.getEffectiveDays(),
					(int)(coupon.getValidEnd().getTime()-coupon.getValidStart().getTime())/ (1000 * 60 * 60 * 24), 
					"验证生成优惠券有效开始时间与结束时间相隔"+couponbatch.getEffectiveDays()+"天");
        }
        //小时
        else if(couponbatch.getEffectiveType()==1 && couponbatch.getEffectiveTimeType()==1)
        {
			Logger.verifyEquals(couponbatch.getEffectiveDays(),
					(int)(coupon.getValidEnd().getTime()-coupon.getValidStart().getTime())/ (1000 * 60 * 60), 
					"验证生成优惠券有效开始时间与结束时间相隔"+couponbatch.getEffectiveDays()+"天");
        }
        else if(couponbatch.getEffectiveType()==0)//优惠券批次是绝对时间
        {
			Logger.verifyEquals(couponbatch.getAcquireStartTime(),coupon.getValidStart(), "验证生成优惠券有效开始时间与 批次有效开始时间一致");
			Logger.verifyEquals(couponbatch.getAcquireEndTime(),coupon.getValidEnd(), "验证生成优惠券有效结束时间与 批次有效结束时间一致");
        }
       }
    }
}